5f25d79f3b2a3fd5f5c94913375828a1871964d3,community/main/java/org/neo4j/index/impl/lucene/LuceneTransaction.java,LuceneTransaction,doCommit,#,226
Before Change
}
applyDocuments( writer, type, documents );
if ( writer != null )
{
dataSource.closeWriter( writer );
}
dataSource.invalidateIndexSearcher( identifier );
}
// TODO Set last committed txId
After Change
for ( Map.Entry<IndexIdentifier, CommandList> entry :
this.commandMap.entrySet() )
{
if ( entry.getValue().isEmpty() )
{
continue;
}
boolean isRecovery = entry.getValue().isRecovery();
IndexIdentifier identifier = entry.getKey();
IndexType type = identifier == LuceneCommand.CreateIndexCommand.FAKE_IDENTIFIER ? null :
dataSource.getType( identifier );
IndexWriter writer = null;
IndexSearcher searcher = null;
CommandList commandList = entry.getValue();
Map<Long, DocumentContext> documents = new HashMap<Long, DocumentContext>();
for ( LuceneCommand command : commandList.commands )
{
if ( command instanceof CreateIndexCommand )
{
CreateIndexCommand createCommand = (CreateIndexCommand) command;
dataSource.indexStore.setIfNecessary( createCommand.getName(),
createCommand.getConfig() );
continue;
}
if ( writer == null )
{
if ( isRecovery )
{
writer = dataSource.getRecoveryIndexWriter( identifier );
}
else
{
writer = dataSource.getIndexWriter( identifier );
writer.setMaxBufferedDocs( commandList.addCount + 100 );
writer.setMaxBufferedDeleteTerms( commandList.removeCount + 100 );
}
searcher = dataSource.getIndexSearcher( identifier ).getSearcher();
}
if ( command instanceof ClearCommand )
{
documents.clear();
dataSource.closeWriter( writer );
writer = null;
dataSource.deleteIndex( identifier );
dataSource.invalidateCache( identifier );
if ( isRecovery )
{
dataSource.removeRecoveryIndexWriter( identifier );
}
continue;
}
Object entityId = command.entityId;
long id = entityId instanceof Long ? (Long) entityId : ((RelationshipId)entityId).id;
DocumentContext context = documents.get( id );
if ( context == null )
{
Document document = LuceneDataSource.findDocument( type, searcher, id );
context = document == null ?
new DocumentContext( identifier.entityType.newDocument( entityId ) /*type.newDocument( entityId )*/, false, id ) :
new DocumentContext( document, true, id );
documents.put( id, context );
}
String key = command.key;
Object value = command.value;
if ( command instanceof AddCommand ||
command instanceof AddRelationshipCommand )
{
type.addToDocument( context.document, key, value );
dataSource.invalidateCache( identifier, key, value );
}
else if ( command instanceof RemoveCommand )
{
type.removeFromDocument( context.document, key, value );
dataSource.invalidateCache( identifier, key, value );
}
else
{
throw new RuntimeException( "Unknown command type " +
command + ", " + command.getClass() );
}
}
applyDocuments( writer, type, documents );
if ( writer != null && !isRecovery )
{
dataSource.closeWriter( writer );
dataSource.invalidateIndexSearcher( identifier );
}
}